<template>
  <div class="list">
    <div class="item" v-for='item of letters'
      @click = 'handleBtnClick'
      :key='item'
      :ref='item'
      @touchStart = handleTouchStart
      @touchMove = handleTouchMove
      @touchEnd = handleTouchEnd
    >{{item}}</div>
  </div>
</template>
<script>
export default{
  name: 'alphabet',
  props: {
    cities: Object
  },
  data () {
    return {
      touchStatus: false
    }
  },
  computed: {
    letters () {
      const letters = []
      for (let i in this.cities) {
        // letters.push(this.cities[i])
        letters.push(i)
      }
      return letters
    }
  },
  methods: {
    handleBtnClick (e) {
      console.log(e.target.innerText)
      this.$emit('change', e.target.innerText)
    },
    handleTouchStart () {
      this.touchStatus = true
    },
    handleTouchMove (e) {
      if (this.touchStatus) {
        const startY = this.$refs['A'][0].offsetTop
        const touchY = e.touch[0].clientY - 79
        const index = Math.floor((touchY - startY) / 20)
        // console.log(index)
        this.$emit('change', this.letters[index])
      }
    },
    handleTouchEnd () {
      this.touchStatus = false
    }
  }
}
</script>
<style lang="stylus" scoped>
@import '~styles/varibles.styl'
.list
  display: flex
  flex-direction: column
  justify-content: center
  text-align: center
  position: absolute
  right: 0
  top: 1.5rem
  bottom: 0
  width: .4rem
  .item
    color: $bgcolor
    height: .44rem
    line-height: .44rem
</style>
